import re


def camel_to_snake(name: str) -> str:
    s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
    return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()


def clamp(n: int, min: int, max: int) -> int:
    if n < min:
        return min
    if n > max:
        return max
    return n
